function gspan (cobj) {
	while(true){
		if(cobj.nextSibling.nodeName!="SPAN")
			cobj=cobj.nextSibling;
		else
			return cobj.nextSibling;
	}
}

function check (obj,info,fun,click) {
	var sp=gspan(obj);
	obj.onfocus = function () {
	    
	    sp.innerHTML = info;
	    sp.className = "stats2";
	}

	obj.onblur=function  () {
		
		if(fun(this.value)){
			sp.innerHTML="输入正确";
			sp.className="stats4";
		}else{
			sp.innerHTML=info;
			sp.className="stats3";

		}
	}
	if (click == "click") {
	    obj.onblur();

	}

}

onload=regs;

function regs(click) {
    var stat = true;
	var username=document.getElementsByName('username')[0];
	var password=document.getElementsByName('password')[0];
	var repass=document.getElementsByName('repass')[0];
	var email=document.getElementsByName('email')[0];
	var codeImage = document.getElementsByName('Chkcode')[0];

	 check(username,"用户名的长度要在3-20之间",function(val){

	     if (val.match(/^\S+$/) && val.length >= 3 && val.length <= 20) 
        {	return true }
		else{
			stat=false;
			return false;
		}
			
	},click);

check(password, "密码必须在6-20位之间", function (val) {
		if(val.match(/^\S+$/)&&val.length>=6&&val.length<=20)
			{return true;}
		else{
			stat=false;
			return false;
		}

	},click)

check(repass, "确认密码要和上面的一直，规则也要相同", function (val) {
		if(val.match(/^\S+$/)&&val.length>=6&&val.length<=20 &&val==password.value)
			{return true;}
		else{
			stat=false;
			return false;
		}
	},click)

check(email, "要按邮箱规则输入", function (val) {

		if(val.match(/\w+@\w+\.\w/))
			{return true;}
		else{
			stat=false;
			return false;
		}
    }, click)

check(codeImage, "请输入图片上的文字", function (val) {

        if (val.match(/\d/) )
        { return true; }
        else {
            stat = false;
            return false;
        }
    }, click)


	return stat;
	//alert(gspan(username));
}

function checkUserName() {


    nameFound();

    return false;
}

function nameFound() {
    
    var str = $("#UserName")[0].value;
    var jsondata = "{'userName':'" + str + "'}";
    var username = document.getElementsByName('username')[0];
    var sp = gspan(username);

    if (str == "") {
        sp.innerHTML = "提醒：请输入用户名！";
        sp.className = "stats2";
    }
    else {
        $.ajax({
            type: "Post",
            url: "Regist.aspx/checkUserName",
            data: jsondata,
            contentType: "application/json;charset=utf-8", // 这句可不要忘了。
            dataType: "json",
            success: function (msg) {
                sp.innerHTML = msg.d;

            },
            error: function () {
                // 错误处理 
                sp.innerHTML = "chucuo";
            }

        });
    }


}



$(function () {
    $("#refrushCodeImage").click(function () {
        newCheckCode();
    });
    $("#codeImage").click(function () {
        newCheckCode();
    });
});
function newCheckCode() {//刷新验证码
    $("#codeImage").attr("src", "../Validata.aspx?a=" + Math.random());
}



function fillInfoCheck() {

    return false;


}

